import { View } from "../../../mvc/core/View";
import { NationalTreasureInfo } from "../../model/NationalTreasureInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { SecTimerView } from "../common/SecTimerView";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { LayerManager } from "../../manager/LayerManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class NationalTreaIcon
    
    export  class NationalTreaIcon extends View
    {
        constructor()
        {
            super();
            if (NationalTreaIcon._instance) 
            {
                throw new Error("NationalTreaIcon 单例");
            }
            this.initUI();
            return;
        }

        public updateData(arg1: NationalTreasureInfo): void
        {
            this._info = arg1;
            if (arg1.activeTime) 
            {
                this._timerView.setParse(HTMLUtil.addColor(Language.getString(27053) + " mm: ss", "#ffff00"));
                this._timerView.setLeftTime(arg1.timeLeft);
            }
            else if (arg1.checkInStart) 
            {
                if (arg1.dateDis > 0) 
                {
                    this._timerView.setParse(HTMLUtil.addColor(Language.getString(27052) + " mm: ss", "#ffff00"));
                    this._timerView.timeOutHandler = this.onTimeOutHandler;
                    this._timerView.setLeftTime(arg1.dateDis);
                }
                else 
                {
                    this._timerView.setParse(HTMLUtil.addColor(Language.getString(27053) + " mm: ss", "#ffff00"));
                    this._timerView.setLeftTime(arg1.timeLeft);
                }
            }
            else 
            {
                this._timerView.setParse(HTMLUtil.addColor(Language.getString(27053) + " mm: ss", "#ffff00"));
                this._timerView.setLeftTime(0);
            }
            return;
        }

        public changeScene(): void
        {
            if (Cache.instance.nationalTrea.inActiveScene()) 
            {
                this.hideLightMask();
            }
            return;
        }

        /* internal  */onTimeOutHandler(): void
        {
            if (this._info) 
            {
                this._timerView.setParse(HTMLUtil.addColor(Language.getString(27053) + " mm: ss", "#ffff00"));
                this._timerView.setLeftTime(this._info.timeLeft);
            }
            return;
        }

        public showLightMask(): void
        {
            if (!this._lightMask) 
            {
                this._lightMask = ObjectPool.getObject(LightMask);
                this._lightMask.transform.matrix = new Object /* flash.geom.Matrix */();
                this._lightMask.x = 0;
                this._lightMask.y = 2;
                this._lightMask.scaleX = 55 / 42.5;
                this._lightMask.scaleY = 54 / 42.5;
                this._lightSprite.addChild(this._lightMask);
            }
            return;
        }

        public hideLightMask(): void
        {
            if (this._lightMask) 
            {
                if (this._lightMask.parent) 
                {
                    this._lightMask.parent.removeChild(this._lightMask);
                }
                this._lightMask.x = 0;
                this._lightMask.y = 0;
                this._lightMask.width = 40;
                this._lightMask.height = 40;
                ObjectPool.disposeObject(this._lightMask);
                this._lightMask = null;
            }
            return;
        }

        /* internal  */initUI(): void
        {
            buttonMode = true;
            this._nationalTreaIconBtn = ObjCreate.createGLoadedButton(ResFileConst.NationalTreaIcon, 0, 0, 50, 50, this);
            addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            this._timerView = new SecTimerView();
            this._timerView.setParse(HTMLUtil.addColor(Language.getString(27052) + " mm: ss", "#ffff00"));
            this._timerView.x = -4;
            this._timerView.y = this._nationalTreaIconBtn.y + this._nationalTreaIconBtn.height;
            this._timerView.mouseEnabled = false;
            this._timerView.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timerView.height = 20;
            this._timerView.filters = [FilterConst.nameGlowFilter];
            addChild(this._timerView);
            this._lightSprite = new Object /* flash.display.Sprite */();
            this._lightSprite.mouseEnabled = false;
            this._lightSprite.mouseChildren = false;
            addChild(this._lightSprite);
            layer = LayerManager.rightTopUILayer;
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureIconClick));
            return;
        }

        public stageResize(arg1: int, arg2: int): void
        {
            this.x = arg1;
            this.y = arg2;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (Cache.instance.nationalTrea.inActiveScene()) 
            {
                this.hideLightMask();
            }
            else 
            {
                this.showLightMask();
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._info = null;
            this._timerView.dispose();
            this.hideLightMask();
            return;
        }

        public static get instance(): NationalTreaIcon
        {
            if (!NationalTreaIcon._instance) 
            {
                NationalTreaIcon._instance = new NationalTreaIcon();
            }
            return NationalTreaIcon._instance;
        }

        /* internal */ /* var */_nationalTreaIconBtn: GLoadedButton;

        /* internal */ /* var */_timerView: SecTimerView;

        /* internal */ /* var */_info: NationalTreasureInfo;

        /* internal */ /* var */_lightMask: LightMask;

        /* internal */ /* var */_lightSprite: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_instance: NationalTreaIcon;
    }
